jQuery(document).ready(function(){
	$j("#progress").fadeIn("slow");
	$j("#progress #pmessage").text("Please wait... system is loading accounting...");

	$j.ajax({
	  type: "POST",
	  url: domain+"accounting/groups/add/aboutgroup",
	  data: "action=start",
	  error: function(msg){
			$j("#progress").addClass("progress-error");
			$j("#progress #pmessage").text("Ops! There was error with loading... Please report problem!");
	  },
	  success: function(content){
	    $j("#tabs").append(content);
	    $j("#progress #pmessage").text("Loaded... ");
	    setTimeout('$j("#progress").fadeOut("slow");', 2000);
	  }
	});
	
	$j("#next_permissions").bind("click", function(){
		$j("#progress").removeClass("progress-error");
		$j("#progress").fadeIn("slow");
		$j("#notice").fadeOut("fast");
		$j("#progress #pmessage").text("Please wait... system is sending data...");
		
		var url = $j("#addaccgroup_form").attr("action");
		var name = $j("#name").attr("value");
		var sdesc = $j("#shortdescriptions").attr("value");
		var accept = $j("#accept").attr("value");
		var cstatus = $j("#cstatus").attr("value");
		var type = $j("#type").attr("value");
		var description = $j("#description").attr("value");

		$j("#name").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#shortdescription").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#cstatus").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#type").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#description").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});
						
		$j.ajax({
			type: "POST",
			url:  url,
			data: "name="+name+"&accept="+accept+"&status="+cstatus+"&sdesc="+sdesc+"&type="+type+"&description="+description,
			dataType: "json",
			success: function ( data, status ){
				
				if ( data.status == "false" )
				{
					if (! data.next )
					{
						$j("#progress").addClass("progress-error");
						$j("#progress #pmessage").text(data.message);
						$j("#"+data.input).css({
							backgroundColor: "#b70a33",
							color: "#fff",
							border: "1px #d80e3d solid"
						});	
					}
					else if ( data.next !== '0')
					{
						$j("#notify_next").fadeIn("fast");
						
					}
				}
				else if ( data.status == "true" )
				{
					$j("#progress").removeClass("progress-error");
					$j("#progress #pmessage").text(data.message);
					
					if ( data.task == "2" )
					{
						$j("#progress").fadeIn("slow");
						$j("#progress #pmessage").text("Please wait... system is loading permissions...");
						$j.ajax({
						  type: "POST",
						  url: domain+"accounting/groups/add/permissions",
						  data: "action=start",
						  error: function(msg){
								$j("#progress").addClass("progress-error");
								$j("#progress #pmessage").text("Ops! There was error with loading... Please report problem!");
						  },
						  success: function(content){
						    document.getElementById("tabs").innerHTML = content;
						    $j("#progress #pmessage").text("Loaded... ");
						    setTimeout('$j("#progress").fadeOut("slow");', 2000);
						  }
						});
					}
				}
				
			}
		});
	});

	$j("#save").bind("click", function(){
		$j("#progress").removeClass("progress-error");
		$j("#progress").fadeIn("slow");
		$j("#notice").fadeOut("fast");
		$j("#progress #pmessage").text("Please wait... system is sending data...");
		
		var url = $j("#addaccgroup_form").attr("action");
		var name = $j("#name").attr("value");
		var sdesc = $j("#shortdescription").attr("value");
		var accept = $j("#accept").attr("value");
		var cstatus = $j("#cstatus").attr("value");
		var type = $j("#type").attr("value");
		var description = $j("#description").attr("value");
		
		$j("#name").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#shortdescription").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#cstatus").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#accept").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});

		$j("#description").css({
			backgroundColor: "white",
			color: "#8a8a8a",
			border: "1px #ccc solid"
		});
						
		$j.ajax({
			type: "POST",
			url:  url,
			data: "name="+name+"&accept="+accept+"&status="+cstatus+"&sdesc="+sdesc+"&type="+type+"&description="+description,
			dataType: "json",
			success: function ( data, status ){
				
				if ( data.status == "false" )
				{
					$j("#progress").addClass("progress-error");
					$j("#progress #pmessage").text(data.message);
					$j("#"+data.input).css({
						backgroundColor: "#b70a33",
						color: "#fff",
						border: "1px #d80e3d solid"
					});	
				}
				else if ( data.status == "true" )
				{
					$j("#progress").removeClass("progress-error");
					$j("#progress #pmessage").text(data.message);
					$j("#notice").fadeIn("normal");
				}
				
			}
		});
	});	
	
	
	$j("#discard").bind("click", function(){
		
		var conf = confirm ( "Do you really want to discard current modifications?" );
		if ( conf )
		{
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			setTimeout ( 'document.location="http://localhost/engine/backend/accounting"', 3000 );	
		}
		else
		{
			$j("#progress #pmessage").text("Canceled...");
			$j("#progress").fadeIn("slow");
			setTimeout ( '$j("#progress").fadeOut("normal");', 3000 );	
		}
		
	});	
	
	$j("#notice_ok").bind("click", function(){
			
			$j("#notice").fadeOut("normal");
			$j("#progress").fadeOut("fast");
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			setTimeout ( 'document.location="http://localhost/engine/backend/accounting"', 3000 );	
	});	
	

	$j("#wizzard_ok").bind("click", function(){
			$j("#progress").removeClass("progress-error");
			$j("#notify_next").fadeOut("normal");
			$j("#progress").fadeIn("fast");
			$j("#progress #pmessage").text("Please wait...");
	
	});	

	$j("#wizzard_not").bind("click", function(){
	    	$j("#progress").removeClass("progress-error");
		 	$j("#notify_next").fadeOut("normal");
			$j("#progress").fadeOut("fast");
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			setTimeout ( 'document.location="http://localhost/engine/backend/accounting"', 3000 );
	});	
	
	$j("#close2").bind("click", function(){
		    $j("#progress").removeClass("progress-error");
			$j("#notify_next").fadeOut("normal");
			$j("#notice").fadeOut("normal");
			$j("#progress").fadeOut("fast");
			$j("#progress #pmessage").text("Please wait...");
			$j("#progress").fadeIn("slow");
			setTimeout ( 'document.location="http://localhost/engine/backend/accounting"', 3000 );	
	});	
			
	$j("#notice_not").bind("click", function(){
			$j("#notice").fadeOut("normal");
			$j("#progress").fadeOut("fast");
	});	
	
	$j("#close").bind("click", function(){
			$j("#notice").fadeOut("normal");
			$j("#progress").fadeOut("fast");
	});	
});